<?php
/**
 * Created by JetBrains PhpStorm.
 * User: 蒋文书
 * Date: 14-12-27
 * Time: 下午11:27
 * To change this template use File | Settings | File Templates.
 */

namespace Admin\Controller;
use Think\Controller;


class AlongController extends CommonController{

    /**
     * 单页列表
     * @author jiangwenshu <jiangwenshu1990@126.com>
     */
    public function index(){ 
        $map=array('type'=>'along','lang'=>LANG_SET); 
        $Along = M('Along'); // 实例化Data数据对象
        $count      = $Along->where($map)->count();// 查询满足要求的总记录数 $map表示查询条件
        $Page = new  \Think\Page($count, 10);// 实例化分页类 传入总记录数（这是根据@979137的意见修改的，这个建议非常好！）
        $show       = $Page->show();// 分页显示输出
         // 进行分页数据查询
        $orderby['id']='desc';
        $list = $Along->where($map)->order($orderby)->limit($Page->firstRow.','.$Page->listRows)->select();
        $this->assign('list',$list);// 赋值数据集
        $this->assign('page',$show);// 赋值分页输出
        $this->meta_title = '单页管理';
        $this->display();
    }

    /**
     * 新增单页
     * @author jiangwenshu <jiangwenshu1990@126.com>
     */
    public function add(){
        if(IS_POST){
            //添加所属角色
            if(D('Along')->add()){
                 $this->success('新增成功！',U('index'));
            }else{
                 $this->error('新增失败！');
            }
        }
        $this->meta_title = '新增单页';
        $this->display();
    }

    /**
     * 删除单页
     * @author jiangwenshu <jiangwenshu1990@126.com>
     */
    public function del(){  
        $id =I('id',0,'intval');
        if(D('Along')->del($id)){
            $this->success('删除成功',U('Index',array('lang'=>LANG_SET)));
        }else{
            $this->error('删除失败！');
        }
    }

    /**
     * 删除用户
     * @author jiangwenshu <jiangwenshu1990@126.com>
     */
    public function edit(){
        $id = I('id',0,'intval');
        if(IS_POST){
           if(D('Along')->update($id,I('lang'))){
                $this->success('更新成功',U('Index',array('lang'=>LANG_SET)));
            }else{
                $this->error('更新失败！');
            }
        }else{
            $this -> info = D('Along')->info($id,I('lang'));
        }
        $this -> meta_title = '编辑';
        $this->display();
    }

    /**
     * ueditor
     * @author jiangwenshu <jiangwenshu1990@126.com>
     */
    public function editor(){
        $setting = C('EDITOR_UPLOAD');
        $this -> uploader = new Upload($setting, 'LOCAL');
        $img   = $this->uploader->upload();
        $return = array();
        $return['url'] = $img['upfile']['savepath'].$img['upfile']['savename'];
        $title = htmlspecialchars($_POST['pictitle'], ENT_QUOTES);
        $return['title'] = $title;
        $return['original'] = $img['upfile']['name'];
        $return['state'] = ($img)? 'SUCCESS' : $this->uploader->getError();
        $this->ajaxReturn($return);
    }
    
}